package euler;
import java.util.ArrayList;


public class Primes {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		ArrayList<Long> primes = new ArrayList<Long>();
		
		for (long zahl=2;zahl<2000000; zahl++) {
			boolean divisible=false;
									
			for (int primeIdx=0;
						primeIdx<primes.size() 
						&& !divisible 
						&& primes.get(primeIdx)<Math.sqrt((double)zahl)+1;
						primeIdx++) {
				if (zahl % primes.get(primeIdx)==0) {
					divisible=true;
				}				
			}
			if (!divisible) {
				primes.add(zahl);
			}
			//if ((zahl % 1000)==0) System.out.println(zahl+" ");
		}
		
		long sumPrimes=0;
		for (long prime : primes) {
			sumPrimes=sumPrimes+prime;
		}

		
		System.out.println("Fertig sumPrimes="+sumPrimes);
		
		long testFactors=Long.parseLong("600851475143");
		for (int primeIdx=0;
		primeIdx<primes.size() 
		
		&& primes.get(primeIdx)<Math.sqrt((double)testFactors)+1;
		primeIdx++) {
		if (testFactors % primes.get(primeIdx)==0) {
			System.out.println("primefactor:"+primes.get(primeIdx));
		}
		
		
        }
		System.out.println("1.st prime="+primes.get(0));
		System.out.println("10 001.st prime="+primes.get(10000));
		
	}
	
	

}
